package com.mrd.util;

import com.mrd.gtimp.business.service.cargoDeclaration.component.CargoDeclarationHelper;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by dengdc on 2017/5/26.
 */
public class PropertiesUtil{
    public static final Properties PROPERTIES = new Properties();
    public static final String[] propertiesFiles = {CargoDeclarationHelper.class.getResource("/cargoDecla/config.properties").getPath()};

    public static String getConfigProperties(String propertyName) {
        if(PROPERTIES.isEmpty()) {
            getConfigProperties();
        }

        return PROPERTIES.getProperty(propertyName);
    }

    private static Properties getConfigProperties() {
        if(!PROPERTIES.isEmpty()) {
            return PROPERTIES;
        } else {
            Properties prop = new Properties();
            try {
                for (String propertiesFile : propertiesFiles) {
                    prop.load(new FileInputStream(propertiesFile));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            PROPERTIES.putAll(prop);
//            PROPERTIES.putAll(SpringUtils.getConfigProperties());
            return PROPERTIES;
        }
    }
}
